# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gsl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7.1
pkgrel=2
pkgdesc="The GNU Scientific Library (GSL) is a modern numerical library for C and C++ programmers (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.gnu.org/software/gsl/gsl.html"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/gsl/${_realname}-${pkgver}.tar.gz")
sha256sums=('dcb0fbd43048832b757ff9942691a8dd70026d5da0ff85601e52687f6deeb34b')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  # Use predefined variables in pkgconfig files (#17541)
  find "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig" -type f -name '*.pc' \
    -exec sed -i -e "s|${MINGW_PREFIX}/include|\${prefix}/include|g" \
    -e "s|${MINGW_PREFIX}/lib|\${prefix}/lib|g" {} \;
}
